Skip to content

Conversation

@CODEBRAKERBOYY
Copy link

📌 Description

This PR adds a new snippet getAncestorTasks under the Utilities/ folder.
The function retrieves all parent tasks in a hierarchy chain (e.g. incidents, problems, changes) by traversing the parent field until the root task is reached.

🛠️ Details

Works with any task-like table that has a parent field.

Returns an array of ancestor GlideRecords, ordered from immediate parent up to root.

Includes cycle detection and depth limit (default 10) to avoid infinite loops.

Useful for rollups, reporting, and escalation logic.

✅ Example Usage
var chain = getAncestorTasks('incident', current.sys_id, 20);
for (var i = 0; i < chain.length; i++) {
gs.info("Ancestor #" + (i+1) + ": " + chain[i].getDisplayValue('number'));
}

🔗 Why It’s Useful

This snippet provides a reusable utility for scenarios where developers need to:

Display full parent task hierarchies.

Aggregate data across parent chains.

Implement escalations or rollup calculations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant